<?php
// ------------------------------------------------------------------------- 
//	pledge
//		Copyright 2004, Array
// 		http://www.picharddesign.com
//	Template
//		Copyright 2004 Thomas Hill
//		<a href="http://www.worldware.com">worldware.com</a>
// ------------------------------------------------------------------------- 
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

// Include any constants used for internationalizing templates.
if ( file_exists(XOOPS_ROOT_PATH ."/modules/pledge/language/".$xoopsConfig['language']."/templates.php") ) 
    require_once XOOPS_ROOT_PATH ."/modules/pledge/language/".$xoopsConfig['language']."/templates.php";
else 
	include_once XOOPS_ROOT_PATH ."/modules/pledge/language/english/templates.php";
// Include any common code for this module.
require_once(XOOPS_ROOT_PATH ."/modules/pledge/include/pledge_includes.php");

function showRecent()
{
	global $xoopsDB;

	// You can get values from xoops_version.php
	// For example, if xoops_version.php has this line (and this is block 1)
	//	$modversion['blocks'][1]['options']	= 1 | "two";
	// Then uncomment the next line
	// $option_value = ($options) ? $options[0] : 128;
	// To retrieve the value 1, (or a default of 128, if not set.)
	
	//get block config
	if(!$_SESSION['recent_number_2_show']){
		$queryString = "SELECT recent_number_2_show,recent_show_date,recent_show_amount FROM " . $xoopsDB->prefix('pledge_station_info') . "";
		$result = $xoopsDB->query($queryString);
		if ( $result ) {
				$myrow = $xoopsDB->fetchArray($result);
					$_SESSION['recent_number_2_show'] = $myrow['recent_number_2_show'];
					$_SESSION['recent_show_date'] = $myrow['recent_show_date'];
					$_SESSION['recent_show_amount'] = $myrow['recent_show_amount'];
			} 
		}


	$block = array();

	$queryString = "SELECT * FROM " . $xoopsDB->prefix('pledge_recent') . " ORDER BY date desc LIMIT ".$_SESSION['recent_number_2_show']."";

	$error = null;
	$result = $xoopsDB->query($queryString);
	if (!$result)
	{
		$msg = $xoopsDB->error();
		if (!$msg)
			$msg = "An error occurred";
		$error = array('msg' => $msg, 'data' => $queryString);
	}

	while (!$error and ($link = $xoopsDB->fetchArray($result)))
	{
		$block[] = $link;
	}
	
	if(count($block) > 0){
	setlocale(LC_MONETARY, 'en_US');
	for ($i = 0; $i < count($block); $i++) {
		$block[$i]['amountFormat'] = money_format('%.0n', $block[$i]['amount']);
		$block[$i]['dateFormat'] = date("m/d/y", $block[$i]['date']);
		$block[$i]['name'] = stripslashes($block[$i]['name']);
	}
	
		
	$all = array
	(
		"data" => $block,
		"lang" => pledge_get_intl(),
		"error" => $error,
		"recent_show_date" => $_SESSION['recent_show_date'],
		"recent_show_amount" => $_SESSION['recent_show_amount']
	);
	  return $all;
	}else{
	  return false; 
	}
}
?>